<?php
/**
 * Created by IntelliJ IDEA
 * Author: 张伯发
 * Date  : 2019/11/1
 * Time  : 16:56
 */

namespace App\Common\Utils;


class DataUtil
{
    /**
     * 对数据进行处理，进行分组
     * @param array $data
     * @param string $key
     * @return mixed
     */
    public static function groupHandle(array $data, string $key)
    {
        $groupArr = array();
        if (empty($data)) return $groupArr;

        foreach ($data as $item) {
            $k     = $item[$key];                       // 分组的key
            $groupArr[$k][] = $item;                    // 进行分组
        }
        return $groupArr;
    }
}
